package com.ate.javamvp.mvp.presenter;

import android.util.Log;

import com.ate.javamvp.MyObserver;
import com.ate.bean.GoodsBean;
import com.ate.bean.SearchBean;
import com.ate.javamvp.mvp.contract.Contract;
import com.ate.javamvp.mvp.model.DataModel;
import com.ate.ui.LoginActivity;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author Ate
 * @description:
 * @date :2020/12/16 13:23
 */
public class DataPresneter extends Contract.DataXiaPresenter {

    private LoginActivity loginActivity;
    private DataModel dataModel;
    Observer<GoodsBean> oberver = new MyObserver<GoodsBean>() {
        @Override
        public void onNext(GoodsBean goodsBean) {
            Log.e("",""+goodsBean.getMsg());
            List<GoodsBean.DataBean> data = goodsBean.getData();
            mView.onSuccess(data);
        }

        @Override
        public void onError(Throwable e) {
            Log.e("",""+e.getMessage());
        }
    };

    public DataPresneter(Contract.DataXiaView mView) {
        super(mView);
    }

    @Override
    protected void setmModel() {
        super.setmModel();
        dataModel = new DataModel();
        loginActivity = new LoginActivity();
    }

    @Override
    public void getGoods() {
        dataModel.getGoods()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(oberver);
    }

    Observer<SearchBean> observer1 = new MyObserver<SearchBean>() {
        @Override
        public void onNext(SearchBean searchBean) {
            mView.onSucc(searchBean.getData());
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            Log.e("",""+e.getMessage());
        }
    };
    public void getSearchGoods(String keyword , String type){
        dataModel.getSearch(keyword,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer1);

    }


}
